<div id="tb<?php echo $uniqid;?>" style="padding:5px">
    <table cellspacing="0" cellpadding="0">
        <tbody>
		<tr>
			<td><a href="javascript:void(0);" onclick="authsAdd();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-tianjia1"></i><span class="l-btn-text">增加</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="authsEdit();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">编辑</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="authsDelete();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span class="l-btn-text">删除</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="authsReload();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
			<td>&nbsp&nbsp;<input id="authsKeywords" style="width:100px" type="text"
								  class="easyui-input textbox"></td>
			<td><a href="javascript:void(0);" onclick="authsSearch();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
		</tr>
        </tbody>
    </table>
</div>

<div class="con" onselectstart="return false;" style="-moz-user-select:none;">
    <table id="auths"></table>
</div>

<div id="authsdlg" class="easyui-dialog" style="width:720px; height:460px;" title="信息框" closed="true"></div>

<script>
    var authsAdd = function () {
		let title= '权限添加';
		let url = '/admin/system/authsadd';
		$('#rightTabs').tabs('close', title);
		addTab(title, url);
    };
    var authsEdit = function () {
		var row = $('#auths').treegrid('getSelected');
		if (row) {
			let title= '权限编辑';
			let url = '/admin/system/authsedit?id=' + row.id;
			$('#rightTabs').tabs('close', title);
			addTab(title, url);
		} else {
			$.messager.alert('提示', '请先选择要编辑的行！', 'warning');
		}
    };
    var authsDelete = function () {
        var row = $('#auths').treegrid('getSelected');
        if (row) {
            $.messager.confirm('提示', '确定删除吗？', function (r) {
                if (r == true) {
                    $.messager.progress();
                    $.post('/admin/system/authsdelete', {id: row.id}, function (data) {
                        $.messager.progress('close');
                        if (data.code == '200') {
                            $.messager.show({
                                title: '提示',
                                msg: data.msg,
                                timeout: 3000,
                                showType: 'slide'
                            });
                            authsReload();
                        } else {
                            $.messager.alert('提示', data.msg, 'warning');
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.alert('提示', '请先选择要删除的行！', 'warning');
        }
    };
    var authsReload = function () {
        $("#auths").treegrid('reload');
    };
    var authsSearch = function () {
		var height = $(window).height() - $(".top").height() - 68;//表格高度
		var width = $(window).width() - $(".leftmenu").width() - 13;//表格高度
        $("#auths").treegrid({
            title: '权限列表',
            width: width,
            height: height,
            singleSelect: true,//如果为true，则只允许选择一行
            striped: true,//是否显示斑马线效果。
            rownumbers: true,//如果为true，则显示一个行号列。
            pagination: true,//是否显示分页
            pageSize: 10,
            pageList: [10, 15, 20, 25],
            method: 'post',
            sortName: 'sortorder',
            sortOrder: 'desc',
            idField: 'id',
            treeField: 'authname',
            url: '/admin/system/authsGet',
            queryParams: {keywords: $('#authskeywords').val()},
            fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
            selectOnCheck: false,
            checkOnSelect: true,
            toolbar: '#tb<?php echo $uniqid;?>',
            columns: [[
                {field: 'authname', title: '权限名', width: '15%'},
                {field: 'controller', title: '控制器', width: '10%'},
                {field: 'action', title: '方法', width: '40%'},
                {field: 'sortorder', title: '排序', width: '5%'},
                {field: 'created_at', title: '创建时间', width: '10%'},
                {field: 'updated_at', title: '更新时间', width: '10%'},
            ]],
            onDblClickRow: function (index, field) {
                authsEdit();
            },
            onLoadSuccess: function (row, data) {
                $.each(data, function (i, val) {
                    //$('#auths').treegrid('collapseAll', data[i].id);
                });
            }
        });
    };
    authsSearch();
</script>
